package com.mate.cloud.auth.service.impl;

import com.mate.cloud.auth.entity.SysUser;
import com.mate.cloud.auth.service.SysUserService;
import jakarta.annotation.Resource;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @description:    java类作用描述
 * @author:         MI
 * @email:          448341911@qq.com
 * @createTime:     2025/2/3 16:58
 * @updateUser:     MI
 * @updateTime:     2025/2/3 16:58
 * @updateRemark:   修改内容
 * @version:        v1.0
 */
@Service
public class UserDetailsServiceImpl implements UserDetailsService {


    @Resource
    private SysUserService sysUserService;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        final SysUser sysUser = sysUserService.selectByUsername(username);
        final List<SimpleGrantedAuthority> grantedAuthorityList = Arrays.asList("USER").stream().map(SimpleGrantedAuthority::new).collect(Collectors.toList());

        return new User(username, sysUser.getPassword(), grantedAuthorityList);
    }
}
